#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,u,v,flg[100010],a[100010],xz1,wz,xz2,s,dp[100010],sf;
vector<int> edge[100010];
int dfs(int u,int f){
	if(flg[u]==1&&edge[u][0]==f) dp[u]=a[u];
	for(auto &i:edge[u])
		if(i!=f) dfs(i,u),dp[u]+=dp[i];
	if(dp[u]>2) sf=0;
	if(a[u]&&!dp[u]) sf=0;
	if(dp[u]==2){
		if(a[u]) dp[u]=0;
		else sf=0;
	}
}
signed main(){
	freopen("clean.in","r",stdin);
	freopen("clean.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		xz1=0,xz2=1,s=0,sf=1;
		memset(flg,0,sizeof(flg)),memset(dp,0,sizeof(dp));
		scanf("%lld",&n);
		for(int i=1;i<=n;i++){
			scanf("%lld",&a[i]),edge[i].clear();
			if(a[u]>1) xz2=0;
		}
		for(int i=1;i<n;i++){
			scanf("%lld%lld",&u,&v);
			edge[u].push_back(v),edge[v].push_back(u);
			flg[u]++,flg[v]++;
			if(flg[u]==n-1) xz1=1,wz=u;
			if(flg[v]==n-1) xz1=1,wz=v;	
		}
		for(int i=1;i<=n;i++)
			if(flg[i]>flg[s]) s=i;
		if(xz1){
			int sum=0;
			for(int i=1;i<=n;i++)
				if(i!=wz) sum+=a[i];
			if(sum/2!=a[wz]||(sum&1)){
				printf("NO\n");
				continue;
			}
			for(int i=1;i<=n;i++)
				if(i!=wz&&a[i]>sum/2) sf=0;
			if(!sf){
				printf("NO\n");
				continue;
			}
			printf("YES\n");
			continue;
		}
		if(xz2){
			dfs(s,0);
			if(!sf||dp[s]!=0){
				printf("NO\n");
				continue;
			}
			printf("YES\n");
			continue;
		}
	}
	return 0;
}
